package com.loan.web.pdf.controller.create;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.AjaxResult;
import com.loan.common.enums.BusinessType;
import com.loan.system.create.domain.AssistPdfTableConf;
import com.loan.system.create.service.IAssistPdfTableConfService;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.common.core.page.TableDataInfo;

/**
 * PDF表格配置Controller
 * 
 * @author Sophia
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/system/table")
public class AssistPdfTableConfController extends BaseController
{
    @Autowired
    private IAssistPdfTableConfService assistPdfTableConfService;

    /**
     * 查询PDF表格配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistPdfTableConf assistPdfTableConf)
    {
        startPage();
        List<AssistPdfTableConf> list = assistPdfTableConfService.selectAssistPdfTableConfList(assistPdfTableConf);
        return getDataTable(list);
    }

    /**
     * 导出PDF表格配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "PDF表格配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssistPdfTableConf assistPdfTableConf)
    {
        List<AssistPdfTableConf> list = assistPdfTableConfService.selectAssistPdfTableConfList(assistPdfTableConf);
        ExcelUtil<AssistPdfTableConf> util = new ExcelUtil<AssistPdfTableConf>(AssistPdfTableConf.class);
        util.exportExcel(response, list, "PDF表格配置数据");
    }

    /**
     * 获取PDF表格配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:table:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assistPdfTableConfService.selectAssistPdfTableConfById(id));
    }

    /**
     * 新增PDF表格配置
     */
    @PreAuthorize("@ss.hasPermi('system:table:add')")
    @Log(title = "PDF表格配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistPdfTableConf assistPdfTableConf)
    {
        return toAjax(assistPdfTableConfService.insertAssistPdfTableConf(assistPdfTableConf));
    }

    /**
     * 修改PDF表格配置
     */
    @PreAuthorize("@ss.hasPermi('system:table:edit')")
    @Log(title = "PDF表格配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistPdfTableConf assistPdfTableConf)
    {
        return toAjax(assistPdfTableConfService.updateAssistPdfTableConf(assistPdfTableConf));
    }

    /**
     * 删除PDF表格配置
     */
    @PreAuthorize("@ss.hasPermi('system:table:remove')")
    @Log(title = "PDF表格配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assistPdfTableConfService.deleteAssistPdfTableConfByIds(ids));
    }
}
